<?php

namespace app\admin\model;

use think\Model;


class LitestoreRequest extends Model
{
    // 表名
    protected $name = 'litestore_request';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'info_type_text',
        'publish_time_text'
    ];
    

    

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getInfoTypeList()
    {
        return ['1' => __('Info_type 1'), '2' => __('Info_type 2'), '3' => __('Info_type 3'), '4' => __('Info_type 4'), '5' => __('Info_type 5')];
    }


    public function getInfoTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['info_type']) ? $data['info_type'] : '');
        $list = $this->getInfoTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function getPublishTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['publish_time']) ? $data['publish_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPublishTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
